1465B - Fair Numbers - CodeForces Solution


brute force math number theory *1000

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

#define ll long long

#define endl "\n"
#define ite iterator
#define input(v)    \
      for (auto &v : v) \
      cin >> v
#define output(v)  \
      for (auto v : v) \
      cout << v << " "
#define Max_size 107374181
#define pb(n) push_back(n)
#define sortv(v) sort(v.begin(), v.end())
#define input2(v)     \
      for (auto &i : v)   \
        for (auto &a : i) \
      cin >> a
#define output2(v)      \
      for (auto &i : v)     \
      {                     \
        for (auto &a : i)   \
          cout << a << " "; \
        cout << "\n";       \
      }




void EssamGhanem()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


//                                          Functions :



                // Problem Solution
vector<ll>binary_vec,anc , dic;
ll dic_binary (ll l , ll r  , ll key ){
    ll mid = (l+r)/2;
    if(r<l)
    {
        return -1;
    }
    if(dic[mid]==key)
    {
        return mid;
    }
    else if(dic[mid] > key )
    {
        return dic_binary(mid+1,r ,key);

    }
    else if (dic[mid]<key)
    {

        return dic_binary(l , mid-1, key);
    }


return 0 ;


}

ll anc_binary (ll l , ll r  , ll key )
{
    ll mid = (l+r)/2;

    if(r<l)
    {
       return -1;
    }


    if(anc[mid]==key)
    {
        return mid;
    }
    else if(anc[mid] > key )
    {

        return anc_binary(l , mid-1, key);
    }
    else if (anc[mid]<key)
    {

        return anc_binary(mid+1,r ,key);
    }


return 0;


}


void solve() {

ll n ;
ll index = 1,d,flag =1;
cin >> n;

while(flag)
{
    index=1;
    while(index <= n)
    {
        index*=10;
        d=(n%index)/(index/10);
        if(d==0)
            continue;
        if(n%d !=0)
        {
            n++;
            flag=1;
            break;

        }

        flag=0;
    }


}
cout << n<<endl;




}








//       ************************************************************************************

//                       #      main      #

int main()
{
     EssamGhanem();
     ll t = 1;
     cin >> t;
     while(t--)
     {
         solve();
     }
}


Comments

Submit
0 Comments
More Questions

579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold